package com.orion.async;

import com.orion.util.SmallTool;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * 带有异步方法的bean
 *
 * @author Administrator
 */
@Component
public class OtherClazzWithAsyncTaskMethod {

    @Async
    public Future<String> customFutureTask() {
        String result = doTask();
        return AsyncResult.forValue(result);
    }


    public String doTask() {
        SmallTool.sleepMillis(5 * 1000);
        return "do Task by thread ：" + Thread.currentThread().getName();
    }

    @Async("llcThreadPoolTaskExecutor")
    public Future<String> customFutureTaskByCustomPool() {
        String result = doTask();
        return AsyncResult.forValue(result);
    }

}
